﻿using CronExpressionDescriptor;

namespace NiuBeService
{
    /// <summary>
    /// Cron表达式帮助类
    /// </summary>
    public static class CronHelper
    {
        /// <summary>
        /// 获取Cron表达式的描述信息
        /// </summary>
        /// <param name="cron"></param>
        /// <returns></returns>
        public static string CronDescription(this string cron)
        {
            try
            {
                if (string.IsNullOrEmpty(cron))
                {
                    return "#";
                }
                return ExpressionDescriptor.GetDescription(cron, new CronExpressionDescriptor.Options { Locale = "zh-CN" });
            }
            catch
            {
                return "#";
            }
        }
        /// <summary>
        /// 检查是否是Cron表达式
        /// </summary>
        /// <param name="cron"></param>
        /// <returns></returns>
        public static bool IsCron(this string cron)
        {
            try
            {
                ExpressionDescriptor.GetDescription(cron, new CronExpressionDescriptor.Options { Locale = "zh-CN" });
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
